package com.sh.双指针;

/**
 * @Auther: sh
 * @Version 1.0
 * @Description:
 */
public class 移动零 {
    public static void main(String[] args) {
        int [] nums = new int[]{0,1,0,3,12};
        moveZeroes(nums);
        for (int num : nums) {
            System.out.println(num);
        }

    }
    public static void moveZeroes(int[] nums) {
//        int fast = 0;
//        for (int i = 0; i < nums.length; i++) {
//            if (nums[i] != 0) {
//                nums[fast] = nums[i];
//                fast++;
//            }
//        }
//        for(int j=fast;j<nums.length;j++){
//            nums[j] = 0;
//        }
//

        int left = 0, right = 0;
        while (right<nums.length){
            if (nums[right]!=0){
                int temp = nums[left];
                nums[left] = nums[right];
                nums[right] = temp;
                left++;
            }
            right++;
        }
    }
}

